import re
#ip addressr'(\d{1,3}\.){3}\d{1,3}$
#身份证号码：\d{17}[0-9X]
#iphone:1\d{10}
#mail:.+@.+\..+

# !/usr/bin/python
# -*- coding: UTF-8 -*-

import re

phone = "2004-959-559 # 这是一个国外电话号码"

# 删除字符串中的 Python注释
num = re.sub(r'#.*$', "", phone)
print("电话号码是: ", num)


# 删除非数字(-)的字符串
num = re.sub(r'\D', "", phone)
print("电话号码是 : ", num)


import re

line = "Cats are smarter than dogs";

matchObj = re.match(r'cats', line, re.M | re.I)
if matchObj:
    print("match --> matchObj.group() : ", matchObj.group())

else:
    print("No match!!")


matchObj = re.search(r'dogs', line, re.M | re.I)
if matchObj:
    print( "search --> matchObj.group() : ", matchObj.group())

else:
    print("No match!!")
ab={}
def inputPhone():
    while (True):
        phone = input("请输入电话号码")
        flag = True
        if len(phone) != 11:
            print('输入有误,重新输入')
            flag = False
            continue
        for c in phone:
            if (c < '0') or (c > '9'):
                print('输入有误，重新输入')
                flag = False
                break
        if (flag): break
    return phone


def inputPhone2():
    while (True):
        phone = input("请输入身份证号码")
        if re.match(r'.+@.+\..+', phone):
            return phone



name=input("请输入姓名：")

ab[name]=inputPhone2()

print('%s的身份证号码是：%s'%(name,ab[name]))



